(function () {
  let React = require('react/addons');
  let jQuery = require('jquery');
  let injectTapEventPlugin = require('react-tap-event-plugin');
  let Main = require('./components/main.jsx');
  let Join = require('./components/join.jsx');
  let Blog = require('./components/blog.jsx');
  let Post = require('./components/post.jsx');
  let Search = require('./components/search.jsx');
  let EditPost = require('./components/edit-post.jsx');
  let NewPost = require('./components/new-post.jsx');
  let ManagePost = require('./components/manage-post.jsx');
  let ManageWordAndComment = require('./components/manage-word-and-comment.jsx');

  window.React = React;
  window.$ = jQuery;

  window.baseUrl = "http://lb.lk-life.com/api/";

  $.ajaxSetup({
    crossDomain: true,
    xhrFields: {
      withCredentials: true
    }
  });

  (function ($) {
    $.isBlank = function (string) {
      return (!string || $.trim(string) === "");
    };
  })(jQuery);

// Parse URL Queries Method
  (function ($) {
    $.getQuery = function (query) {
      query = query.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
      var expr = "[\\?&]" + query + "=([^&#]*)";
      var regex = new RegExp(expr);
      var results = regex.exec(window.location.href);
      if (results !== null) {
        return results[1];
        return decodeURIComponent(results[1].replace(/\+/g, " "));
      } else {
        return false;
      }
    };
  })(jQuery);

  let url = location.href;

  if (url.includes("join.html")) {
    React.render(<Join/>, document.body);
  } else if (url.includes("blog.html")) {
    React.render(<Blog/>, document.body);
  } else if (url.includes("new-post.html")) {
    React.render(<NewPost/>, document.body);
  } else if (url.includes("manage-post.html")) {
    React.render(<ManagePost/>, document.body);
  } else if (url.includes("edit-post.html")) {
    React.render(<EditPost/>, document.body);
  } else if (url.includes("post.html")) {
    React.render(<Post/>, document.body);
  } else if (url.includes("search.html")) {
    React.render(<Search/>, document.body);
  } else if (url.includes("manage-word-and-comment.html")) {
    React.render(<ManageWordAndComment/>, document.body);
  } else {
    React.render(<Main/>, document.body);
  }

})();
